package com.ssm.card.server.controller.card;


import com.github.pagehelper.PageInfo;
import com.jee.ssm.common.support.Const;
import com.jee.ssm.common.utils.UUIDFactory;
import com.jee.ssm.common.web.json.Tip;
import com.jee.ssm.common.web.param.ParamMap;
import com.ssm.card.dao.model.card.Card;
import com.ssm.card.dao.model.estate.Estate;
import com.ssm.card.dao.model.residence.Residence;
import com.ssm.card.rpc.api.building.BuildingService;
import com.ssm.card.rpc.api.card.CardService;
import com.ssm.card.rpc.api.residence.ResidenceService;
import com.ssm.card.rpc.api.unit.UnitService;
import com.ssm.upms.dao.model.Account;
import com.ssm.upms.log.AdminControllerLog;
import com.ssm.upms.rpc.api.ssm.AccountService;
import com.ssm.upms.server.controller.ssm.AdminBaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.util.*;

/**
* 门禁管理 Controller
* @author GaoXiang
* @version 1.0
*/
@Controller
@RequestMapping("/card")
public class CardController extends AdminBaseController<Card> {


    /**
     * 进入门禁添加页面 携带一个生成的id --> longId
     * @param model 返回的实体容器
     * @return 添加页面
     */
    @RequestMapping(value="/add")
    @RequiresPermissions("card:add")
    public String add(HttpServletRequest request, ModelMap model){
        HttpSession session = request.getSession();
        Account account = (Account)session.getAttribute(Const.ACCOUNT);
        model.put("type",account.getType());
        /*if(account.getType()==21) {
            model.put("residence", residenceService.selectById(account.getInfoId().split(",")[1]));
        }*/
        model.put("longId", UUIDFactory.getStringId());
        return "manager/card/add";
    }

    /**
     * 进入门禁添加页面 携带一个生成的id --> longId
     * @param model 返回的实体容器
     * @return 添加页面
     */
    @RequestMapping(value="/addCard")
    public String addCard(HttpServletRequest request, ModelMap model){
        HttpSession session = request.getSession();
        Account account = (Account)session.getAttribute(Const.ACCOUNT);
        model.put("type",account.getType());
       /* if(account.getType()==21) {
            model.put("residence", residenceService.selectById(account.getInfoId().split(",")[1]));
        }*/
        return "manager/card/addCard";
    }





    /**
     * 进入门禁编辑页面
     * @param model 返回门禁的容器
     * @param id 门禁id
     * @return 编辑页面
     */
    @RequestMapping(value="/edit")
    @RequiresPermissions("card:edit")
    public String edit(HttpServletRequest request, ModelMap model, @RequestParam String id) throws ParseException  {
        HttpSession session = request.getSession();
        Account account = (Account)session.getAttribute(Const.ACCOUNT);
        model.put("type",account.getType());
        Card card=cardService.selectById(id);
        card.setResidence(residenceService.selectById(card.getResidenceId()));
        card.setBuilding(buildingService.selectById(card.getBuildingId()));
        card.setUnit(unitService.selectById(card.getUnitId()));
 //       card.setUserRoom(ownerService.selectById(card.getUserId()));
        model.put("data",card);
        return "manager/card/edit";
    }

    /**
     * 修改卡失效的时间页面
     * @param cardId
     * @return 页面
     */
    /*@RequestMapping(value="/timeContinue")
    public String timeContinue(String cardId ,String newsId,ModelMap map){
        map.put("newsId",newsId);
        map.put("cardId",cardId);
        return "manager/estate/timeContinue";
    }
*/

    /**
     * 续时页面
     * @param cardId
     * @return 页面
     */
   /* @RequestMapping(value="/addTime")
    public String addTime(String cardId ,ModelMap map){
        map.put("cardId",cardId);
        return "manager/card/addTime";
    }
*/

    /**
     * 修改门禁卡的卡失效
     * @param card
     * @return
     */
   /* @RequestMapping(value = "/appendTime")
    @ResponseBody
    public  Tip appendTime(Card card){
        try {
            cardService.updateById(card);
            return  new Tip();
        } catch (Exception e) {
            e.printStackTrace();
            return  new Tip(1,"卡失效修改失败");
        }
    }
*/



    /**
     * 修改门禁卡的卡失效
     * @param card
     * @return
     */
/*    @RequestMapping(value = "/updateCardAging")
    @ResponseBody
    public  Tip updateCardAging(Card card,String newsId){
        try {
            cardService.updateById(card);
            newsService.deleteById(newsId);
            return  new Tip();
        } catch (Exception e) {
            e.printStackTrace();
            return  new Tip(1,"卡失效修改失败");
        }
    }*/



    /**
     * 门禁添加
     * @param card 带id的门禁对象
     * @return 成功状态
     */
    @RequestMapping(value="/save")
    @ResponseBody
    @RequiresPermissions("card:add")
    @AdminControllerLog(description = "添加门禁" )
    public Tip save(Card card, HttpSession session, String userRoomId)  {
        try {
            if(cardService.count(card.getNumber())>0){
                return new Tip(1,"门禁卡编号已存在！");
             }

            /* if(equipmentService.chooseEquipment(card.getUnitId()) == null) {
                return new Tip(2,"该房产所在单元未添加门禁卡");
             }

             if(userRoomId!=""&& userRoomId!=null){
                UserRoom userRoom= userRoomService.selectById(userRoomId);
                userRoom.setType("1");
                userRoomService.updateById(userRoom);
            }*/
            card.setCreateTime(new Date());
       /*     Account account= (Account) session.getAttribute(Const.ACCOUNT);
                if(account.getType()==1){
                    Residence residence= residenceService.selectById(card.getResidenceId());
                    Estate estate=estateService.selectById(residence.getEstateId());
                    if(estate.getCardNumber()>0){
                        estate.setCardNumber(estate.getCardNumber() - 1);
                        estateService.updateById(estate);
                        card.setEstateId(residence.getEstateId());
                        cardService.insert(card);
                    }else{
                        return new Tip(1,"门禁卡已经用完,请及时购买门禁卡");
                    }

                }else if(account.getType()==2){
                    Estate estate=estateService.selectById(account.getInfoId());
                    if(estate.getCardNumber()>0){
                        estate.setCardNumber(estate.getCardNumber() - 1);
                        estateService.updateById(estate);
                        card.setEstateId(account.getInfoId());
                        cardService.insert(card);
                    }else{
                        return new Tip(1,"门禁卡已经用完,请及时购买门禁卡");
                    }

                }else if(account.getType()==21){
                    Estate estate=estateService.selectById(account.getInfoId().split(",")[0]);
                    if(estate.getCardNumber()>0){
                        estate.setCardNumber(estate.getCardNumber() - 1);
                        estateService.updateById(estate);
                        card.setEstateId(account.getInfoId().split(",")[0]);
                        cardService.insert(card);
                    }else{
                        return new Tip(1,"门禁卡已经用完,请及时购买门禁卡");
                    }

                }*/
                return new Tip();
            } catch (Exception e) {
            e.printStackTrace();
             return new Tip(1,"添加失败！");
         }

    }



    /**
     * 门禁添加
     * @param card 带id的门禁对象
     * @return 成功状态
     */
/*    @RequestMapping(value="/saveCard")
    @ResponseBody
    @AdminControllerLog(description = "添加门禁卡" )
    public Tip saveCard(Card card, Account act, User user, HttpSession session, String roomId, String umType)  {
        String cardId = UUIDFactory.getStringId();
        card.setId(cardId);
        try {
            if(cardService.count(card.getNumber())>0){
                return new Tip(1,"门禁卡编号已存在！");
            }

            if(equipmentService.chooseEquipment(card.getUnitId()) == null) {
                return new Tip(2,"该房产所在单元未添加门禁卡");
            }
            card.setCreateTime(new Date());
            Account account= (Account) session.getAttribute(Const.ACCOUNT);
            if(account.getType()==1){
                Residence residence= residenceService.selectById(card.getResidenceId());
                Estate estate=estateService.selectById(residence.getEstateId());
                 if(estate==null){
                    return new Tip(1,"这个小区没有物业");
                }
                if(estate.getCardNumber()>0){
                    estate.setCardNumber(estate.getCardNumber() - 1);
                    estateService.updateById(estate);
                    card.setEstateId(residence.getEstateId());
                }else{
                    return new Tip(1,"门禁卡已经用完,请及时购买门禁卡");
                }

            }else if(account.getType()==2){
                Estate estate=estateService.selectById(account.getInfoId());
                if(estate.getCardNumber()>0){
                    estate.setCardNumber(estate.getCardNumber() - 1);
                    estateService.updateById(estate);
                    card.setEstateId(account.getInfoId());
                }else{
                    return new Tip(1,"门禁卡已经用完,请及时购买门禁卡");
                }

            }else if(account.getType()==21){
                Estate estate=estateService.selectById(account.getInfoId().split(",")[0]);
                if(estate.getCardNumber()>0){
                    estate.setCardNumber(estate.getCardNumber() - 1);
                    estateService.updateById(estate);
                    card.setEstateId(account.getInfoId().split(",")[0]);
                    cardService.insert(card);
                }else{
                    return new Tip(1,"门禁卡已经用完,请及时购买门禁卡");
                }
            }
            cardService.insert2(card);
            List<Equipment> et =equipmentService.selectByUnitId(card.getUnitId());
            String id = UUIDFactory.getStringId();
            user.setId(id);
            act.setId(UUIDFactory.getStringId());
            act.setInfoId(id);
            userService.insert(user);
            accountService.insert(act);
            UserRoom userRoom =new UserRoom();
            userRoom.setId(UUIDFactory.getStringId());
            userRoom.setRoomId(roomId);
            userRoom.setUnitId(card.getUnitId());
            userRoom.setUserId(id);
            userRoom.setBuildingId(card.getBuildingId());
            userRoom.setType(umType);
            userRoom.setCreateTime(new Date());
            userRoom.setDefaultUser("1");
            userRoom.setStatus("1");
            userRoom.setResidenceId(card.getResidenceId());
            userRoomService.insert(userRoom);
           EquipmentCard ec = new EquipmentCard();
            ec.setId(UUIDFactory.getStringId());
            ec.setType("1");
            ec.setUserId(id);
            ec.setRoomId(roomId);
            ec.setCreateTime(new Date());
            ec.setCardId(cardId);
            ec.setEquipmentId(et.get(0).getId());
            equipmentCardService.insert(ec);
            return new Tip();

        } catch (Exception e) {
            e.printStackTrace();
            return new Tip(1,"添加失败！");
        }

    }*/









    /**
     * 根据 id 修改门禁
     * @param card 带id的门禁对象
     * @return 成功状态
     */
    @RequestMapping(value="/update")
    @ResponseBody
    @RequiresPermissions("card:edit")
    @AdminControllerLog(description = "修改门禁" )
    public Tip update(Card card,HttpServletRequest request) {
        try {
             String id= request.getParameter("id");
            if (!cardService.selectById(id).getNumber().equals(card.getNumber())){
              if(cardService.count(card.getNumber())>0){
                  return new Tip(1,"门禁卡编号已存在！");
              }

            }
            cardService.updateById(card);
            return new Tip();
        } catch (Exception e) {
            //e.printStackTrace();
            return new Tip(1,"修改失败！");
        }

    }


    /**
     * 根据 id 删除门禁
     * @param id 门禁id
     * @return 成功状态
     */
    @RequestMapping(value="/delete")
    @ResponseBody
    @RequiresPermissions("card:delete")
    @AdminControllerLog(description = "删除门禁" )
    public Tip delete(@RequestParam String id) {

        try {
            cardService.deleteById(id);
            return new Tip();
        } catch (Exception e) {
            //e.printStackTrace();
            return new Tip(1,"删除失败！");
        }

    }


    /**
     * 根据 id 列表批量删除
     * @param ids 门禁id List
     * @return 成功状态
     */
    @RequestMapping(value="/deleteByIds")
    @ResponseBody
    @RequiresPermissions("card:delete")
    @AdminControllerLog(description = "批量删除门禁" )
    public Tip deleteByIds(@RequestParam("ids") List<String> ids) {

        try {
            cardService.deleteByIds(ids);
            return new Tip();
        } catch (Exception e) {
            //e.printStackTrace();
            return new Tip(1,"批量删除失败！");
        }

    }


    /**
     * 根据 id 查找门禁
     * @param id 门禁id
     * @return 门禁对象 json
     */
    @RequestMapping(value="/findJson")
    @ResponseBody
    @RequiresPermissions("card:list")
    public Card find(@RequestParam String id) {

        return cardService.selectById(id);
    }


    /**
     * 获取门禁列表 获取全部 不分页
     * @param request 请求参数
     * @return 门禁列表页面
     */
    @RequestMapping(value="/all")
    @RequiresPermissions("card:list")
    public String all(HttpServletRequest request, ModelMap modelMap) {

        return list(request,modelMap,1,0);
    }


    /**
     * 获取门禁列表 分页
     * @param request 请求参数
     * @param page 第几页
     * @param size 每页大小
     * @return 门禁列表页面
     */
    @RequestMapping(value="/list")
    @RequiresPermissions("card:list")
    public String list(HttpServletRequest request, ModelMap modelMap, Integer page, Integer size) {
        HttpSession session=request.getSession();
        Account account= (Account) session.getAttribute(Const.ACCOUNT);
        Date currentDate=new Date();
        ParamMap paramMap=new ParamMap(request);
        paramMap.put("currentDate",currentDate);
        if (account.getType()==2){
            paramMap.put("estateId",account.getInfoId());
        }else if(account.getType()==21){
            paramMap.put("estateId",account.getInfoId().split(",")[0]);
            paramMap.put("residenceNum",account.getInfoId().split(",")[1]);
        }/*else if(account.getType()==5){
            List<PoliceResidence> policeResidenceList= policeResidenceService.findByPoliceId(account.getInfoId());
            List<String> policeIdList=new ArrayList<String>();
            if(policeResidenceList.size()>0){
                for(PoliceResidence pr:policeResidenceList){
                    policeIdList.add(pr.getResidenceId());
                }
            }else {
                policeIdList.add("0");
            }

            paramMap.put("policeIdList", policeIdList);
        }*/
        List<Residence> residences = residenceService.listWithoutPage(paramMap);//搜索下拉框选择小区

        PageInfo<Card> pageInfo=cardService.list(paramMap,page,size);
        try {
            for (Card card:pageInfo.getList()){
                card.setResidence(residenceService.selectById(card.getResidenceId()));
                card.setBuilding(buildingService.selectById(card.getBuildingId()));
                card.setUnit(unitService.selectById(card.getUnitId()));
                //card.setValidDate(TimeUtils.daysBetween(currentDate,card.getCardAging()));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        modelMap.put("residences",residences);//搜索下拉框选择小区
        modelMap.put("type",account.getType());
        modelMap.put("pageInfo",cardService.list(paramMap,page,size));
        modelMap.putAll(paramMap);
        return "manager/card/list";
    }

    /**
     * 小区门禁卡图
     * @return map 统计图
     */
/*

    @RequestMapping(value = "/countName")
    @ResponseBody
    public Map<String, Object> countName(HttpServletRequest request) throws Exception {

        Card meter = new Card();
        HttpSession session=request.getSession();
        Account account= (Account) session.getAttribute(Const.ACCOUNT);

        if(account.getType()==21){
            meter.setResidenceId(account.getInfoId().split(",")[1]);
        }else if(account.getType()==2){
            meter.setEstateId(account.getInfoId());
        }

        Map<String, Object> map = new HashMap<String, Object>();
        List<Card> queryCommunityForList = cardService.countName(meter);
        int length = queryCommunityForList.size();
        String[] nameArray = new String[length];
        List<Echat> list = new ArrayList<Echat>();
        for(int i = 0 ;i<nameArray.length; i++  ){
            nameArray [i] = queryCommunityForList.get(i).getResidenceId();  //获取小区名称
        }
        for(Card community : queryCommunityForList){
            meter.setResidenceId(community.getId());
            Card re = cardService.countNumber(meter);
            Echat echat= new Echat();
            echat.setValue(re.getResidenceId());
            echat.setName(community.getResidenceId());
            list.add(echat);
        }
        map.put("value",list);
        map.put("name",nameArray);
        return map;
    }
*/

    /**
     * 小区门禁卡图
     * @return map 统计图
     */
   /* @RequestMapping(value = "/countName2")
    @ResponseBody
    public Map<String, Object> countName2(HttpServletRequest request) throws Exception {

        Card meter = new Card();
        HttpSession session=request.getSession();
        Account account= (Account) session.getAttribute(Const.ACCOUNT);

        if(account.getType()==21){
            meter.setResidenceId(account.getInfoId().split(",")[1]);
        }else if(account.getType()==2){
            meter.setEstateId(account.getInfoId());
        }

        Map<String, Object> map = new HashMap<String, Object>();

        List<Card> queryCommunityForList = cardService.countName2(meter);
        int length = queryCommunityForList.size();
        String[] nameArray = new String[length];
        List<Echat> list = new ArrayList<Echat>();
        for(int i = 0 ;i<nameArray.length; i++  ){
            nameArray [i] = queryCommunityForList.get(i).getType();  //获取名称
        }
        for(Card community : queryCommunityForList){
            meter.setType(community.getType());
            Card re = cardService.countNumber2(meter);
            Echat echat= new Echat();
            echat.setValue(re.getType());
            echat.setName(community.getType());
            list.add(echat);
        }
        map.put("value",list);
        map.put("name",nameArray);
        return map;
    }*/

    /**
     * 门禁卡时效图数据的统计
     * @param request
     * @return 集合
     * @throws ParseException
     */
    /* @RequestMapping(value = "/countCardAging")
     @ResponseBody
     public Map<String,Object> countCardAging(HttpServletRequest request, HttpSession session) throws ParseException {
         Account account= (Account) session.getAttribute(Const.ACCOUNT);
         Map<String, Object> map = new HashMap<String, Object>();
         String[] nameArray ={"十天之内","十天到二十天之间","二十天到一个月之间","一个月到两个月之间","两个月以上"};
         List<Echat> list = new ArrayList<Echat>();
         Date currentDate=new Date();
         ParamMap paramMap=new ParamMap(request);
         if(account.getType()==2){
             paramMap.put("estateId",account.getInfoId());
         }else if(account.getType()==21){
             paramMap.put("residenceId",account.getInfoId().split(",")[1]);
         }
         paramMap.put("begin",currentDate);
         paramMap.put("end", TimeUtils.addDate(currentDate,10));
         Long count0= cardService.selectByTime(paramMap);
         Echat echat= new Echat();
         echat.setValue(count0.toString());
         echat.setName("十天之内");
         list.add(echat);

         paramMap.put("begin",TimeUtils.addDate(currentDate,10));
         paramMap.put("end", TimeUtils.addDate(currentDate,20));
         Long count1= cardService.selectByTime(paramMap);
         Echat echat1= new Echat();
         echat1.setValue(count1.toString());
         echat1.setName("十天到二十天之间");
         list.add(echat1);

         paramMap.put("begin",TimeUtils.addDate(currentDate,20));
         paramMap.put("end", TimeUtils.addDate(currentDate,30));
         Long count2= cardService.selectByTime(paramMap);
         Echat echat2= new Echat();
         echat2.setValue(count2.toString());
         echat2.setName("二十天到一个月之间");
         list.add(echat2);

         paramMap.put("begin",TimeUtils.addDate(currentDate,30));
         paramMap.put("end", TimeUtils.addDate(currentDate,60));
         Long count3= cardService.selectByTime(paramMap);
         Echat echat3= new Echat();
         echat3.setValue(count3.toString());
         echat3.setName("一个月到两个月之间");
         list.add(echat3);

         paramMap.put("begin",TimeUtils.addDate(currentDate,60));
         paramMap.put("end", TimeUtils.addDate(currentDate,36500));
         Long count6= cardService.selectByTime(paramMap);
         Echat echat6= new Echat();
         echat6.setValue(count6.toString());
         echat6.setName("两个月以上");
         list.add(echat6);
         map.put("value",list);
         map.put("name",nameArray);
         return map;
    }*/

    /**
     * 门禁卡使用时间距离当前时间图统计图
     * @return
     */
    /*@RequestMapping(value = "/countTime")
    @ResponseBody
    public Map<String,Object> countTime(HttpSession session, HttpServletRequest request) throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();
        Account account= (Account) session.getAttribute(Const.ACCOUNT);
        ParamMap paramMap=new ParamMap(request);
        if(account.getType()==2){
            paramMap.put("estateId",account.getInfoId());
        }else if(account.getType()==21){
            paramMap.put("residenceId",account.getInfoId().split(",")[1]);
        }
        List<Record> recordList= recordService.countLastCard(paramMap);
        String[] nameArray ={"一天前","十天前","二十天前","一个月前","两个月前"};
        List<Echat> list = new ArrayList<Echat>();
        Date currentDate=new Date();
        int count=0;int count1=0;int count2=0;int count3=0;int count4=0;
        for(Record re:recordList){
         int days= TimeUtils.daysBetween(re.getOpenTime(),currentDate);
          if(days>=1 && days<10){
              count++;
          }else if(days>=10 && days<20){
            count1++;
          }else if(days>=20 && days<30){
              count2++;
          }else if(days>=30 && days<60){
            count3++;
          }else if(days>=60){
              count4++;
          }
        }
        Echat echat= new Echat();
        echat.setValue(String.valueOf(count));
        echat.setName("一天前");
        list.add(echat);
        Echat echat1=new Echat();
        echat1.setValue(String.valueOf(count1));
        echat1.setName("十天前");
        list.add(echat1);
        Echat echat2=new Echat();
        echat2.setValue(String.valueOf(count2));
        echat2.setName("二十天前");
        list.add(echat2);
        Echat echat3=new Echat();
        echat3.setValue(String.valueOf(count3));
        echat3.setName("一个月前");
        list.add(echat3);
        Echat echat4=new Echat();
        echat4.setValue(String.valueOf(count4));
        echat4.setName("两个月前");
        list.add(echat4);
        map.put("value",list);
        map.put("name",nameArray);
        return map;
    }
*/
    /*@RequestMapping(value="/checklist")
    @RequiresPermissions("card:list")*/
   /* public  String  checklist(HttpServletRequest request, ModelMap modelMap){
        HttpSession session =  request.getSession();
        Account account=(Account) session.getAttribute(Const.ACCOUNT);
        ParamMap paramMap= new ParamMap(request);
        if(account.getType()==2){
            paramMap.put("estateId",account.getInfoId());
        }
        List<Card> list=cardService.checkList(paramMap);
        for (Card card:list){
            card.setResidence(residenceService.selectById(card.getResidenceId()));
            card.setBuilding(buildingService.selectById(card.getBuildingId()));
            card.setUnit(unitService.selectById(card.getUnitId()));
        }

        modelMap.put("list",list);
        return "manager/card/chooseCard";
    }
*/


    /**
     * 查看此卡绑定的信息
     * @param cardId 门禁卡id
     * @return 房产列表
     */
   /* @RequestMapping(value="/equipmentCard")
    public String equipmentCard(ModelMap modelMap, @RequestParam String cardId) {

       List<EquipmentCard> list = equipmentCardService.selectByCardId(cardId);
       for (EquipmentCard equipmentCard:list){
           Room room = roomService.selectById(equipmentCard.getRoomId());
           //根据房间id查询房间信息
           if(room!=null){
               equipmentCard.setResidence(residenceService.selectById(room.getResidenceId()));
               Unit unit = unitService.selectById(room.getUnitId());
               equipmentCard.setUnit(unit);
               equipmentCard.setBuilding(buildingService.selectById(unit.getBuildingId()));
           }

           //查询一下这张卡是否有userId
           if (equipmentCard.getUserId()!=null && !"".equals(equipmentCard.getUserId())){
               modelMap.put("userId",equipmentCard.getUserId());
           }
       }
       modelMap.put("cardId",cardId);
       modelMap.put("list",list);
        return "manager/card/equipmentCard";
    }*/


    /**
     * 给此卡添加新的房产信息
     * @param model
     * @param cardId
     * @return
     */
   /* @RequestMapping(value="/xin")
    public String xin(ModelMap model, String cardId, String userId){
        model.put("cardId",cardId);
        model.put("longId", UUIDFactory.getStringId());
        model.put("userId",userId);
        return "manager/card/xin";
    }*/

    /**
     * 获取用户列表
     * @return 用户列表页面
     */
/*    @RequestMapping(value="/checkUser")
    public String checklist(ModelMap modelMap) {
        List<User> list=userService.chooseUser();
        modelMap.put("list",list);
        return  "manager/card/chooseUser";
    }*/


    /**
     * 一卡绑多个设备 房间
     * @param equipmentCard
     * @return
     */
   /* @RequestMapping(value="/saveNew")
    @ResponseBody
    public Tip saveNew(EquipmentCard equipmentCard,String unitId){
        try {

            Equipment equipment = new Equipment();
            if (unitId !=null && !"".equals(unitId)){
                equipment = equipmentService.chooseEquipment(unitId);//根据单元id查询设备
            }
            if (equipment!=null){
                equipmentCard.setEquipmentId(equipment.getId());
            }
            equipmentCard.setCreateTime(new Date());
            equipmentCard.setType("1");
            equipmentCardService.insert(equipmentCard);
            return new Tip();
        }catch (Exception e){
            return new Tip(1,"添加失败！");
        }
    }

*/
    /**
     * 根据cardID获取所有权限
     * 用于门禁卡授权
     * @param cardId
     * @return 页面
     */
    /*@RequestMapping("/findInfo")
    public String findInfo(String cardId,ModelMap model){

        Card card = cardService.selectById(cardId);
        card.setResidence(residenceService.selectById(card.getResidenceId()));//小区
        List<Building> buildings = buildingService.chooseBuidling(card.getResidenceId());//该小区下的楼栋
        for(Building b : buildings) {
            b.setUnits(unitService.findByBuildingIdCaidId( new Card(cardId,b.getId())));
        }
        model.put("card",card);
        model.put("buildings",buildings);
        return "manager/card/chooseUnits";
    }
*/


    /**
     * 获取小区管理卡 分页
     * @param request 请求参数
     * @param page 第几页
     * @param size 每页大小
     * @return 小区管理卡页面
     */
   /* @RequestMapping(value="/resMangerList")
    @RequiresPermissions("card:resMangerList")
    public String resMangerList(HttpServletRequest request, ModelMap modelMap, Integer page, Integer size) {
        HttpSession session=request.getSession();
        Account account= (Account) session.getAttribute(Const.ACCOUNT);
        ParamMap paramMap=new ParamMap(request);
        if (account.getType()==2){
            paramMap.put("estateId",account.getInfoId());
        }else if(account.getType()==21){
            paramMap.put("residence",account.getInfoId().split(",")[1]);
        }else if(account.getType()==5){
            List<PoliceResidence> policeResidenceList= policeResidenceService.findByPoliceId(account.getInfoId());
            List<String> policeIdList=new ArrayList<String>();
            if(policeResidenceList.size()>0){
                for(PoliceResidence pr:policeResidenceList){
                    policeIdList.add(pr.getResidenceId());
                }
            }else {
                policeIdList.add("0");
            }
            paramMap.put("policeIdList", policeIdList);
        }
        PageInfo<Card> pageInfo=cardService.resMangerList(paramMap,page,size);
        for (Card card:pageInfo.getList()){
            card.setResidence(residenceService.selectById(card.getResidenceId()));
        }
        modelMap.put("pageInfo",pageInfo);
        modelMap.put("type",account.getType());
        modelMap.putAll(paramMap);
        return "manager/card/resMangerList";
    }
*/

    /**
     * 进入小区管理卡添加页面 携带一个生成的id --> longId
     * @param model 返回的实体容器
     * @return 添加页面
     */
/*
    @RequestMapping(value="/resMangerAdd")
    public String resMangerAdd(HttpServletRequest request, ModelMap model){

        HttpSession session = request.getSession();
        Account account = (Account)session.getAttribute(Const.ACCOUNT);
        model.put("type",account.getType());
        if(account.getType()==21) {
            model.put("residence", residenceService.selectById(account.getInfoId().split(",")[1]));
        }


        model.put("longId", UUIDFactory.getStringId());
        return "manager/card/resMangerAdd";
    }
*/


    /**
     * 小区管理卡添加
     * @param card 带id的门禁对象
     * @return 成功状态
     */
  /*  @RequestMapping(value="/saveResManger")
    @ResponseBody
    public Tip saveResManger(Card card,HttpServletRequest request)  {
        try {
            if(cardService.count(card.getNumber())>0){
                return new Tip(1,"门禁卡编号已存在！");
            }
            HttpSession session = request.getSession();
            Account account = (Account)session.getAttribute(Const.ACCOUNT);
            if (account.getType()==2){
                card.setEstateId(account.getInfoId());
            }
            Date date=new Date();
            card.setIntro("小区管理卡");
            card.setCreateTime(date);
            cardService.insertMan(card);
            return new Tip();
        } catch (Exception e) {
            e.printStackTrace();
            return new Tip(1,"添加失败！");
        }

    }

*/

    /**
     * 获取物业管理卡 分页
     * @param request 请求参数
     * @param page 第几页
     * @param size 每页大小
     * @return 物业管理卡页面
     */
  /*  @RequestMapping(value="/estMangerList")
    @RequiresPermissions("card:estMangerList")
    public String estMangerList(HttpServletRequest request, ModelMap modelMap, Integer page, Integer size) {
        HttpSession session=request.getSession();
        Account account= (Account) session.getAttribute(Const.ACCOUNT);
        ParamMap paramMap=new ParamMap(request);
        if (account.getType()==2){
            paramMap.put("estateId",account.getInfoId());
        }else if(account.getType()==5){
            List<PoliceResidence> policeResidenceList= policeResidenceService.findByPoliceId(account.getInfoId());
            List<String> policeIdList=new ArrayList<String>();
            if(policeResidenceList.size()>0){
                for(PoliceResidence pr:policeResidenceList){
                    policeIdList.add(pr.getResidenceId());
                }
            }else {
                policeIdList.add("0");
            }
            paramMap.put("policeIdList", policeIdList);
        }
        PageInfo<Card> pageInfo=cardService.estMangerList(paramMap,page,size);
        for (Card card:pageInfo.getList()){
            card.setEstate(estateService.selectById(card.getEstateId()));
        }
        modelMap.put("pageInfo",pageInfo);
        modelMap.put("type",account.getType());
        modelMap.putAll(paramMap);
        return "manager/card/estMangerList";
    }
*/

    /**
     * 进入物业管理卡添加页面 携带一个生成的id --> longId
     * @param model 返回的实体容器
     * @return 添加页面
     */
  /*  @RequestMapping(value="/estMangerAdd")
    public String estMangerAdd(HttpServletRequest request, ModelMap model){

        HttpSession session = request.getSession();
        Account account = (Account)session.getAttribute(Const.ACCOUNT);
        model.put("type",account.getType());
        if(account.getType()==2) {
            model.put("estate", estateService.selectById(account.getInfoId()));
        }

        model.put("longId", UUIDFactory.getStringId());
        return "manager/card/estMangerAdd";
    }
*/

    /**
     * 物业管理卡添加
     * @param card 带id的门禁对象
     * @return 成功状态
     */
   /* @RequestMapping(value="/saveEstManger")
    @ResponseBody
    public Tip saveEstManger(Card card)  {
        try {
            if(cardService.count(card.getNumber())>0){
                return new Tip(1,"门禁卡编号已存在！");
            }
            Date date=new Date();
            card.setIntro("物业管理卡");
            card.setCreateTime(date);
            cardService.insertMan(card);
            return new Tip();
        } catch (Exception e) {
            e.printStackTrace();
            return new Tip(1,"添加失败！");
        }
    }
*/
    /**
     * 根据cardID获取所有权限
     * 用于门禁卡授权
     * @param cardId
     * @return 页面
     */
    /*@RequestMapping("/EstMangerTree")
    public String findTree(String cardId,ModelMap model){

        Card card = cardService.selectById(cardId);
        card.setEstate(estateService.selectById(card.getEstateId()));//物业
        List<Building> buildings = new ArrayList<>();
        List<Residence> residences = residenceService.listByEstateId(card.getEstateId());//根据物业id查小区
        for (Residence r : residences){
             buildings = buildingService.chooseBuidling(r.getId());
                for (Building b :buildings){
                    List<Unit> units = unitService.findByBuildingId(b.getId());
                    b.setUnits(units);
                    b.setUnits(unitService.findByBuildingIdCaidId( new Card(cardId,b.getId())));
                }
            r.setBuildings(buildings);
        }
        model.put("card",card);
        model.put("residences",residences);
        return "manager/card/estMangerTree";
    }


*/
    //---------------------------- property -------------------------------

    @Resource
    private CardService cardService;

    @Resource
    private ResidenceService residenceService;

    @Resource
    private BuildingService buildingService;

    @Resource
    private UnitService unitService;

/*    @Resource
    private EquipmentCardService equipmentCardService;

    @Resource
    private EquipmentService equipmentService;*/

/*    @Resource
    private RoomService roomService;*/

/*    @Resource
    private UserService userService;*/

/*    @Resource
    private EstateService estateService;

    @Resource
    private RecordService recordService;

    @Resource
    private  UserRoomService userRoomService;*/

    @Resource
    private AccountService accountService;

  /*  @Resource
    private NewsService newsService;
*/
  /*  @Resource
    private PoliceResidenceService policeResidenceService;*/
}
